package com.light.boot_demo.listener;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ansi.AnsiColor;
import org.springframework.boot.ansi.AnsiOutput;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;


@Slf4j
@Configuration
@Order(Ordered.HIGHEST_PRECEDENCE)
public class StartedListener implements ApplicationListener<ApplicationStartedEvent> {


    @Override
    public void onApplicationEvent(ApplicationStartedEvent event) {
        this.printStartInfo();
    }

    private void printStartInfo() {

        log.info(AnsiOutput.toString(AnsiColor.BRIGHT_BLUE, "Server started at         "));
        log.info(AnsiOutput.toString(AnsiColor.BRIGHT_BLUE, "Server admin started at   "));
        log.info(AnsiOutput.toString(AnsiColor.BRIGHT_YELLOW, "Server has started successfully!"));
    }

}


//ApplicationFailedEvent：该事件为spring boot启动失败时的操作
//
//        ApplicationPreparedEvent：上下文context准备时触发
//
//        ApplicationReadyEvent：上下文已经准备完毕的时候触发
//
//        ApplicationStartedEvent：spring boot 启动监听类
//
//        SpringApplicationEvent：获取SpringApplication
//
//        ApplicationEnvironmentPreparedEvent：环境事先准备
